﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Reuse.PCL.Extensions
{
    /// <summary>
    /// Handler for the RaiseNetworkError event
    /// </summary>
    /// <param name="sender">Object that triggers the event</param>
    /// <param name="e">Instance of NetworkErrorEventArgs</param>
    public delegate void NetworkErrorEventHandler( object sender, NetworkErrorEventArgs e );
    /// <summary>
    /// Handler for the RaiseParseError event
    /// </summary>
    /// <param name="sender">Object that triggers the event</param>
    /// <param name="e">Instance of ParseErrorEventArgs</param>
    public delegate void ParseErrorEventHandler( object sender, ParseErrorEventArgs e );

    /// <summary>
    /// EventArgs for the RaiseNetworkError event
    /// </summary>
    public class NetworkErrorEventArgs : EventArgs
    {
        /// <summary>
        /// Client connectivity error, used when code reaches the HttpRequestException exception
        /// </summary>
        public bool IsConnectivityError { get; set; }
        /// <summary>
        /// Server error, happens when StatusCode is 400+ from HttpResponseMessage or IsSuccessStatusCode equals false
        /// </summary>
        public bool IsServerError { get; set; }
        /// <summary>
        /// The exception caught when in a try catch structure
        /// </summary>
        public Exception ExceptionCaught { get; set; }
        /// <summary>
        /// Identifier of organization unit for which the error happened
        /// </summary>
        public string Token { get; set; }
    }

    /// <summary>
    /// EventArgs for the ParseErrorEventArgs event
    /// </summary>
    public class ParseErrorEventArgs : EventArgs
    {
        /// <summary>
        /// No results error, happens when there is a successful response from the server but there is no data available
        /// </summary>
        public bool NoResults { get; set; }
        /// <summary>
        /// Parsing error, happens when there is a parsing exception reading or converting a serialized object or property 
        /// </summary>
        public bool IsParseError { get; set; }
        /// <summary>
        /// The exception caught when in a try catch structure
        /// </summary>
        public Exception ExceptionCaught { get; set; }
        /// <summary>
        /// Identifier of organization unit for which the error happened
        /// </summary>
        public string Token { get; set; }

    }
}
